package dailearn.stream.output;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

/**
 * @author daify
 * @date 2019-07-14
 */
@EnableBinding(MessageSource.class)
public class SendMessageService {

    @Autowired
    @Output(MessageSource.OUT_PUT)
    private MessageChannel channel;

    /**
     * 消息发送
     * @param msg
     */
    public void sendMsg(String msg) {
        channel.send(MessageBuilder.withPayload(msg).build());
        System.err.println("消息发送成功："+msg);
    }

}
